package com.dzirtbry.miner.UI;

import com.dzirtbry.miner.controller.PaneController;
import com.dzirtbry.miner.model.Pane;
import com.dzirtbry.miner.settings.GameSettings;

import javax.swing.*;
import java.awt.*;

/**
 * User: dzirtbry
 * Date: 2/26/12
 * Time: 5:42 PM
 */
public class Field extends JPanel {

    private PaneController controller;
    private Pane pane;
    private GameSettings gameSettings;

    public Field() {
        init();
    }

    private void init() {
        setPreferredSize(new Dimension(400, 400));
    }

    private void upateState() {

    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(Color.BLACK);
        g.drawLine(0, 0, 0, this.getHeight());
        g.drawLine(0, 0, this.getWidth(), 0);
        g.drawLine(0, this.getHeight(), this.getWidth(), this.getHeight());
        g.drawLine(this.getWidth(), 0, this.getWidth(), this.getHeight());


        Dimension d = gameSettings.getPaneDimension();
        int boxHeight = this.getHeight() / d.height;
        int boxWidth = this.getWidth() / d.width;
        for (int i = 0; i < d.height; i++) {
            for (int j = 0; j < d.width; j++) {
                g.drawRect(i * boxWidth, j * boxHeight, (i + 1) * boxWidth, (j + 1) * boxHeight);
            }
        }

//        Toolkit.getDefaultToolkit().getImage("flag.png");
        g.drawImage(Toolkit.getDefaultToolkit().getImage("flag.png"), 0, 0, this);
    }

    public PaneController getController() {
        return controller;
    }

    public void setController(PaneController controller) {
        this.controller = controller;
    }

    public Pane getPane() {
        return pane;
    }

    public void setPane(Pane pane) {
        this.pane = pane;
    }

    public GameSettings getGameSettings() {
        return gameSettings;
    }

    public void setGameSettings(GameSettings gameSettings) {
        this.gameSettings = gameSettings;
    }
}
